﻿using CRMG.Container.Source.Helper;
using CRMG.Container.Source.Variables;
using System;
using System.Collections;
using System.Drawing;
using System.Globalization;
using System.Resources;
using System.Threading;
using System.Windows.Forms;
using Telerik.WinControls.UI;

namespace CRMG.Container.Views.BaseList
{
    public partial class FrmMessage : Telerik.WinControls.UI.RadForm
    {
        TableLayoutPanel tbl;
        ResourceManager formRes;
        public FrmMessage(string header, Hashtable h)
        {
            try
            {
                InitializeComponent();
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(AppVariables.ApplicationCulture);
                formRes = new ResourceManager("CRMG.Container.Resources.ControlResources.WinFormStrings", typeof(FrmMessage).Assembly);
                this.Text = header;
                btnClose.Text = formRes.GetString("Close");
                tbl = new TableLayoutPanel();
                tbl.Dock = DockStyle.Fill;
                tbl.AutoScroll = true;
                tbl.ColumnStyles.Add(new ColumnStyle() { SizeType = SizeType.Percent, Width = 40.0F });
                tbl.ColumnStyles.Add(new ColumnStyle() { SizeType = SizeType.Percent, Width = 60.0F });
                IDictionaryEnumerator idictEnm = h.GetEnumerator();
                int rw = 0;
                bool isLong = false;
                while (idictEnm.MoveNext())
                {
                    isLong = idictEnm.Value.ToStr().Length < 21;
                    tbl.RowStyles.Add(new RowStyle() { SizeType = SizeType.Absolute, Height = isLong ? 50.0F : 80.0F });
                    RadLabel rdbl = CreateLabel(idictEnm.Key.ToStr() + " :");
                    tbl.Controls.Add(rdbl, 0, rw);
                    if (isLong == true)
                    {
                        RadTextBox rdx = CreateTextBox(idictEnm.Value.ToStr());
                        tbl.Controls.Add(rdx, 1, rw);
                    }
                    else
                    {
                        RichTextBox rdx = CreateRichTextBox(idictEnm.Value.ToStr());
                        tbl.Controls.Add(rdx, 1, rw);
                    }
                    rw++;
                }
                tblLytMain.Controls.Add(tbl, 0, 0);
            }
            catch (Exception)
            {
                throw;
            }
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private RichTextBox CreateRichTextBox(string text)
        {
            RichTextBox rtx = new RichTextBox();
            rtx.Dock = DockStyle.Fill;
            rtx.Font = this.Font;
            rtx.ReadOnly = true;
            rtx.Text = text;
            rtx.BackColor = Color.White;
            return rtx;
        }

        private RadTextBox CreateTextBox(string text)
        {
            RadTextBox rtx = new RadTextBox();
            rtx.Anchor = AnchorStyles.Top;
            rtx.Font = this.Font;
            rtx.ReadOnly = true;
            rtx.Text = text;
            rtx.AutoSize = true;
            return rtx;
        }

        private RadLabel CreateLabel(string text)
        {
            RadLabel rdbl = new RadLabel();
            rdbl.Text = text;
            rdbl.Font = this.Font;
            rdbl.Anchor = AnchorStyles.Left | AnchorStyles.Top;
            rdbl.AutoSize = true;
            return rdbl;
        }
    }
}
